package tools
{
	import model.vo.Navigate;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	public class NavigateCreator
	{
		private var _xml:XML=<navigate></navigate>;
		public function NavigateCreator()
		{
		}
		public function getXmlNaviagte(list:ArrayCollection):XML{
			var i:int=0;
			for each(var navigate:Navigate in list){
				if(navigate.parentId==0){
					var parent:Navigate=navigate;
					_xml.appendChild(createChild(navigate));
					var j:int=0;
					for each(var navigate2:Navigate in list){
						if(navigate2.parentId==parent.id){
							_xml.child[i].appendChild(createChild(navigate2));
							var parent2:Navigate=navigate2;
							
							for each(var navigate3:Navigate in list){
								if(navigate3.parentId==parent2.id){
									_xml.child[i].child[j].appendChild(createChild(navigate3));
								}
							}
							j++;
						}
					}
					i++;
				}
			}
			return _xml;
		}
		
		
		private function createChild(navigate:Navigate):XML{
			var xml:XML=<child></child>
			xml.@id=navigate.id;
			xml.@label=navigate.name;
			xml.@parentId=navigate.parentId;
			return xml;			
		}	
	}
}